package au.com.bus4u.config;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;


@Configuration
public class InterceptorConfigurer implements WebMvcConfigurer {


    /**
     * 	跨域问题
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowedOrigins("*");
    }


    @Value("${spring.profiles.uploads}")
    private String uploads;//图片项目url访问路径

    @Value("${upload.file.path}")
    private String uploadFilePath;//配置文件配置的物理保存地址

    /**
     *	spring boot 映射访问项目之外的静态资源
     *
     *	浏览器访问路径	/uploads/**
     *
     *	映射访问路径	"file:"+uploadFilePath
     *
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //	/uploads/**
        registry.addResourceHandler("/"+uploads+"**").addResourceLocations("file:"+uploadFilePath);

        WebMvcConfigurer.super.addResourceHandlers(registry);
    }

}
